package rongyao;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class test2 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        boolean flag = false;
        for (int i = 2; i <= 16; i++) {
            String s = Integer.toString(n, i);
            if (valid(s)) {
                System.out.println(i);
                flag = true;
            }
        }
        if (!flag) System.out.println(-1);
    }

    public static boolean valid(String s){
        char[] chars = s.toCharArray();
        for (int left = 0, right = chars.length - 1; left < right; left++, right--) {
            if (chars[left] != chars[right]) return false;
        }
        return true;
    }
}
